package com.ganlinux.pangoo.controller.restful.footmark;

import com.alibaba.fastjson.JSON;
import com.ganlinux.pangoo.controller.restful.base.BaseController;
import com.ganlinux.pangoo.dao.model.UserFootmarkList;
import com.ganlinux.pangoo.entity.request.ReqFootPrintCreateUpdate;
import com.ganlinux.pangoo.entity.response.RspFootPrintCreateUpdateData;
import com.ganlinux.pangoo.entity.response.base.RspBase;
import com.jfinal.aop.Before;
import com.jfinal.kit.HttpKit;

/**
 * BlogController
 * 所有 sql 与业务逻辑写在 Model 或 Service 中，不要写在 Controller 中，养成好习惯，有利于大型项目的开发与维护
 */
@Before(FootMarkCreateAndUpdateInterceptor.class)
public class FootMarkCreateAndUpdateController extends BaseController {
	public void save() {
		super.save();
		RspBase rspLogin = new RspBase();
		String pin = null;
		boolean isnew = false;
		/*String bodyType = getRequest().getHeader("BodyType");
		if (bodyType == null) {
			rspLogin.setStatus(1);
			rspLogin.setMessage("失败");
		}else {
			if (bodyType.equals("Form")) {
				userid = getParaToInt("userId",-1);
				isnew = getParaToBoolean("createNew",true);
				reqVerifyCode = JsonUtil.fromJson(getPara("footPrintCreateBean"), ReqFootPrintCreateUpdate.class);
			}else {
				String jsonString=(String) getRequest().getParameterMap().keySet().toArray()[0];
				reqVerifyCode= JsonUtil.fromJson(jsonString, ReqFootPrintCreateUpdate.class);
				userid = reqVerifyCode.getUserId();
				isnew = reqVerifyCode.getCreateNew();
			}
		}*/
		String jsonString= HttpKit.readData(getRequest());
		ReqFootPrintCreateUpdate reqFootPrintCreateUpdate = JSON.parseObject(jsonString, ReqFootPrintCreateUpdate.class);
		reqFootPrintCreateUpdate.setReqHeader(getHeaderFromRequest(getRequest()));
		pin = reqFootPrintCreateUpdate.getReqHeader().getPin();
		isnew = reqFootPrintCreateUpdate.getCreateNew();

		if (pin != null && reqFootPrintCreateUpdate != null) {
			RspFootPrintCreateUpdateData rspFootPrintCreateUpdateData = UserFootmarkList.dao.footPrintCreateUpdate(pin,isnew,reqFootPrintCreateUpdate.getFootPrintCreateBean());
			if (rspFootPrintCreateUpdateData != null) {
				rspLogin.setStatus(0);
				rspLogin.setMessage("成功");
				rspLogin.setData(rspFootPrintCreateUpdateData);
				renderJson(rspLogin);
			}else {
				rspLogin.setStatus(1);
				rspLogin.setMessage("失败");
			}

		}else{
			rspLogin.setStatus(1);
			rspLogin.setMessage("失败");
		}
		renderText(JSON.toJSONString(rspLogin));
	}
}


